package com.feiyu.util;

/**
 * @author nanshouxiao@teacher.com.cn
 * @date 2018-08-27 15:53
 */
public class StringUtil {
    /**
     * 获取驼峰式
     * @param name 下划线代码
     * @param isFirstCase 首字母是否大写
     * @return
     */
    public static String getHumName(String name, boolean isFirstCase)
    {
        char[] charArray = name.toCharArray();
        boolean isNeedCase = isFirstCase;
        StringBuilder humName = new StringBuilder();
        for (int i = 0; i < charArray.length; i++)
        {
            char c = charArray[i];
            if (charArray[i] == '_')
            {
                isNeedCase = true;
                continue;
            }
            humName.append(isNeedCase && c >= 'a' ? (char)(c ^ 0x20) : c);
            isNeedCase = false;
        }
        return humName.toString();
    }

    /**
     *  获取驼峰式，首字母小写
     * @param name
     * @return
     */
    public static String getHumName(String name)
    {
        return getHumName(name, false);
    }
}
